/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.orm.testdesign;

import java.util.HashMap;

import org.testis.orm.refinedclasses.TestDesignTreeNode;

/**
 * 
 * @author nurhat
 */
public class TestPartSaver {

    public static TestDesignTreeNode operationAdd(
	    HashMap<String, Object> parameters, TestDesignTreeNode parentNode,
	    int childIndex, String typeName) {
	TestPartDataHandler handler = null;

	if (typeName.equals("TestSuite")) {
	    handler = new TestSuiteDataHandler();
	} else if (typeName.equals("TestPlan")) {
	    handler = new TestPlanDataHandler();
	} else if (typeName.equals("PreConditionCase")) {
	    handler = new PreConditionDataHandler();
	} else if (typeName.equals("PostConditionCase")) {
	    handler = new PostConditionDataHandler();
	} else if (typeName.equals("TestCaseGroup")) {
	    handler = new TestCaseGroupDataHandler();
	} else if (typeName.equals("TestCase")) {
	    handler = new TestCaseDataHandler();
	} else if (typeName.equals("TestStepGroup")) {
	    handler = new TestStepGroupDataHandler();
	} else if (typeName.equals("TestStep")) {
	    handler = new TestStepDataHandler();
	} else if (typeName.equals("DataObject")) {
	    handler = new DataObjectDataHandler();
	}
	if (handler == null) {
	    return null;
	}
	return handler.operationAdd(parameters, parentNode, childIndex);
    }

    public static boolean operationSave(HashMap<String, Object> parameters,
	    TestDesignTreeNode node) {
	TestPartDataHandler handler = null;

	if (node.getReference().getType().getName().equals("TestSuite")) {
	    handler = new TestSuiteDataHandler();
	} else if (node.getReference().getType().getName().equals("TestPlan")) {
	    handler = new TestPlanDataHandler();
	} else if (node.getReference().getType().getName()
		.equals("PreConditionCase")) {
	    handler = new PreConditionDataHandler();
	} else if (node.getReference().getType().getName()
		.equals("PostConditionCase")) {
	    handler = new PostConditionDataHandler();
	} else if (node.getReference().getType().getName()
		.equals("TestCaseGroup")) {
	    handler = new TestCaseGroupDataHandler();
	} else if (node.getReference().getType().getName().equals("TestCase")) {
	    handler = new TestCaseDataHandler();
	} else if (node.getReference().getType().getName()
		.equals("TestStepGroup")) {
	    handler = new TestStepGroupDataHandler();
	} else if (node.getReference().getType().getName().equals("TestStep")) {
	    handler = new TestStepDataHandler();
	} else if (node.getReference().getType().getName().equals("DataObject")) {
	    handler = new DataObjectDataHandler();
	}
	if (handler == null) {
	    return false;
	}
	return handler.operationSave(parameters, node);
    }
}
